package cn.com.thingo.shyintelligent.presenter;

import javax.inject.Inject;

import cn.com.thingo.shyintelligent.base.RxPresenter;
import cn.com.thingo.shyintelligent.base.contract.SearchEzDeviceContract;
import cn.com.thingo.shyintelligent.model.DataManager;
import cn.com.thingo.shyintelligent.model.bean.EzStatementBean;
import cn.com.thingo.shyintelligent.model.db.UserInfo;
import cn.com.thingo.shyintelligent.model.http.api.EzApis;
import cn.com.thingo.shyintelligent.util.EzHttpUtils;
import cn.com.thingo.shyintelligent.util.RxUtil;
import io.reactivex.functions.Consumer;


public class SearchEzDevicePresenter extends RxPresenter<SearchEzDeviceContract.View> implements SearchEzDeviceContract.Presenter {
    private DataManager dataManager;
    private UserInfo mUserInfo;
    private EzApis mEzApis;

    @Inject
    public SearchEzDevicePresenter(DataManager dataManager) {
        this.dataManager = dataManager;
        mUserInfo = UserInfo.getInstance();
        mEzApis = EzHttpUtils.getInstance().getEzApis();
    }


    @Override
    public void addEzDevicePermission(String statement) {
        addSubscribe(mEzApis.postAddStatement(mUserInfo.getAccessToken(),mUserInfo.getAccountId(),statement).compose(RxUtil.<EzStatementBean>rxSchedulerHelper()).subscribe(new Consumer<EzStatementBean>() {
            @Override
            public void accept(EzStatementBean ezStatementBean) throws Exception {
                mView.viewAddEzDevicePermissionResult(ezStatementBean);
            }
        }));
    }
}
